//
//  AreaViewController.m
//  10803
//
//  Created by student on 16/2/24.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "AreaViewController.h"
#import "ChinaArea.h"
@interface AreaViewController ()<UIPickerViewDelegate,UIPickerViewDataSource>
@property(nonatomic,strong)NSArray *povinces;
@property(nonatomic,strong)NSArray *citys;
@end

@implementation AreaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.povinces=[ChinaArea provinces];
    
    
//    NSString *curState=self.povinces[0];
    self.citys=[ChinaArea cisForProvince:0];
    for(int i=1;i<self.citys.count;i++)
    {
        NSLog(@"%@",self.citys[i]);
    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)pressed:(id)sender
{
    NSInteger sel1=[self.pickview selectedRowInComponent:0];
    NSInteger sel2=[self.pickview selectedRowInComponent:1];
    self.label.text=[NSString stringWithFormat:@"%@,%@",self.povinces[sel1],self.citys[sel2]];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if(component==0)
    {
        return self.povinces.count;
    }
    else
    {
        return self.citys.count;
    }
}
-(nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if(component==0)
    {
        return self.povinces[row];
    }
    else
    {
        NSArray *a=[[NSArray alloc]initWithArray:self.citys[row]];
        NSMutableArray *arr=[[NSMutableArray alloc]init];
        for(int i=0;i<a.count;i++)
        {
            NSDictionary *dic=[[NSDictionary alloc]init];
            dic=a[i];
            [arr addObject:dic[@"city"]];
        }
        return arr[row];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
